-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: static-server can continue if already running #14307
Conversation
cli/test/fixtures/static-server.js
Outdated
await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost'))).then(outcomes => { | ||
if (outcomes.every(o => o.status === 'fulfilled')) return; | ||
if (outcomes.every(o => o.reason.message.includes('already'))) { | ||
return console.warn('😧 Server already up. Continuing…'); | ||
} | ||
console.error(outcomes.map(o => o.reason)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability, will this work?
Also we should probably throw an error if the servers fail for an unknown reason
await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost'))).then(outcomes => { | |
if (outcomes.every(o => o.status === 'fulfilled')) return; | |
if (outcomes.every(o => o.reason.message.includes('already'))) { | |
return console.warn('😧 Server already up. Continuing…'); | |
} | |
console.error(outcomes.map(o => o.reason)); | |
}); | |
const outcomes = await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost'))); | |
if (outcomes.some(o => o.status === 'rejected')) { | |
if (outcomes.every(o => o.reason.message.includes('already'))) { | |
console.warn('😧 Server already up. Continuing…'); | |
} else { | |
console.error(outcomes.map(o => o.reason)); | |
throw new Error('One or more servers did not start correctly'); | |
} | |
} | |
return servers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your await flow is definitely better. and fixes the error throwing. (i was ending up with an unhandled rejection previously)
i do still prefer the style of my two every()s, but whatever. definitely not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamraine thanks for writing out the suggestion! :) so clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approval w/ Adam's suggestions.
fixes #14302
not trying to get fancy. these are pretty unique ports.